﻿	
for /f "tokens=1 delims=: " %%h in ('time /T') do set hour=%%h
for /f "tokens=2 delims=: " %%m in ('time /T') do set minutes=%%m
for /f "tokens=3 delims=: " %%a in ('time /T') do set ampm=%%a
set currenttime=%hour%.%minutes%%ampm%

REM Change below paths accordingly, when you copy this batch file to server

SET Root_Path="C:\Projects\TPProject\CMT1\CMT\Trunk\Executables"
SET Log_Root="C:\Projects\TPProject\CMT1\CMT\Trunk\Executables\Batch_Execution_Logs"
SET Exe_Path=%Root_Path%\EXE\ADAMDataImportService.EXE
SET LOG=%Log_Root%\log_%date%_%currenttime%.log

if exist %Log_Root% goto :ExeRun else :CreateLogFolder

:CreateLogFolder
md %Log_Root%


:ExeRun
echo Date: %date% Time: %time% >>  %LOG%
echo Process starts
echo Process starts>> %LOG%

echo Updating CMT database>> %LOG%

FOR /F "tokens=*" %%i in ('%Exe_Path%') do set TOOLOUTPUT=%%i

IF %TOOLOUTPUT% EQU Failed (goto FailedProcess)
IF %TOOLOUTPUT% EQU NoRecords (goto NoRecords)

echo %TOOLOUTPUT%

goto SuccessProcess

:SuccessProcess

echo Date: %date% Time: %time%>>  %LOG%
ECHO Finished updating database >> %LOG%
goto Exit

:NoRecords

ECHO No changes found in data feed>> %LOG%
goto Exit

:FailedProcess

ECHO Failed to complete updating database>> %LOG%

:Error_Exit

echo Date: %date% Time: %time% >> %LOG%
echo Process finished with errors.Please check log files.>> %LOG%
pause
exit

:Exit 

echo Date: %date% Time: %time% >> %LOG%
echo Process Finished >> %LOG%
pause
exit











